import {LAppDelegate} from '@/app/lib/live2d/lappdelegate';

export class CharacterManager {
    // 单例
    public static getInstance(): CharacterManager {
        if (!this._instance) {
            this._instance = new CharacterManager();
        }

        return this._instance;
    }

    public getLive2dPortraits(): { [key: string]: string } {
        return LAppDelegate.getInstance().getPortraits();
    }

    public getCharacter(): string {
        return LAppDelegate.getInstance().getCharacter();
    }

    public setCharacter(character: string): void {
        LAppDelegate.getInstance().changeCharacter(character);
    }

    public getBackImages(): { [key: string]: string } {
        return LAppDelegate.getInstance().getBackImages();
    }


    public pushAudioQueue(audioData: ArrayBuffer): void {
        this._ttsQueue.push(audioData);
        this.audioRecorderIndex++;
        console.log("推送增加一条，目前条数:" + this.audioRecorderIndex);
    }

    public popAudioQueue(): ArrayBuffer | null {
        if (this._ttsQueue.length > 0) {
            return this._ttsQueue.shift();
        } else {
            return null;
        }
    }

    public getTTSQueueLength(): number {
        return this._ttsQueue.length;
    }

    private static _instance: CharacterManager;
    private _ttsQueue: ArrayBuffer[] = [];
    // 音频录制索引
    public audioRecorderIndex: number = 0;

}